package com.wc.AlgoOJ_train.train1.c8.A805;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/11 21:24
 * @description 数字三角形
 * http://43.138.190.70:8888/p/A805
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int c = sc.nextInt();
        while (c-- > 0) {
            int n = sc.nextInt();
            int[][] tra = new int[n + 1][n + 1];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= i; j++) {
                    tra[i][j] = sc.nextInt();
                }
            }
            for (int i = n; i > 1; i--) {
                for (int j = 1; j < i; j++) {
                    tra[i - 1][j] += Math.max(tra[i][j], tra[i][j + 1]);
                }
            }

            System.out.println(tra[1][1]);
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}



